package com.dengqi.mymodule.activity.fragment.recycleview;

import android.content.Context;
import android.util.AttributeSet;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @Author: dengqi
 * @CreateDate: 2020/11/19 9:12
 * @Description: recycleview+adapter
 */
public class QRecycleView<T> extends RecyclerView {

    private QRecycledapter<T> mAdapter;

    public QRecycleView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setLayoutManager(new LinearLayoutManager(getContext()));
    }


    public void setRecycleViewStyle(QRecycledapter<T> adapter){
        setAdapter(adapter);
    }

    /**
     * 绑定adapter
     * @param adapter
     */
    public void setRecycleAdapter(QRecycledapter<T> adapter){
        this.mAdapter = adapter;
        setAdapter(adapter);
    }

    /**
     * 绑定数据
     * @param data
     */
    public  void setAdapterData(List<T> data){
        mAdapter.setData(data);
        mAdapter.notifyDataSetChanged();
    }

    /**
     * 点击事件
     */
    public void setAdapterClickListener(QRecycledapter.OnItemClickListener<T> onItemClickListener) {
        mAdapter.setOnItemClickListener(onItemClickListener);
    }
}
